package com.runchinaup.textapp.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.runchinaup.textapp.R;

/**
 * Created by liber on 2018/3/5.
 */

/**
 * 一个循环播放的动画
 *
 */
public class BeforeMeasureDialog extends Dialog {

    private Context context;
    private ImageView ref_progress;
    Animation operatingAnim;

    public BeforeMeasureDialog(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog);
        setCancelable(true);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {

        ref_progress = findViewById(R.id.ref_progress);
        ref_progress.setVisibility(View.VISIBLE);
        //关闭的按钮
        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel();
            }
        });

    }

    @Override
    public void show() {
        super.show();
        operatingAnim = AnimationUtils.loadAnimation(getContext(),R.anim.rotate);
        LinearInterpolator lin = new LinearInterpolator();
        operatingAnim.setInterpolator(lin);
        ref_progress.startAnimation(operatingAnim);
    }
}
